package com.sdry.web.controller.llm;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sdry.model.llm.Classes;
import com.sdry.service.llm.ClassesService;
import com.sdry.utils.ResponseUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

/**
 * 班次管理
 * @Title:ClassesController
 * @Package com.sdry.web.controller.llm
 * @author llm
 * @date 2019年1月28日
 * @version 1.0
 */

@Controller
@RequestMapping("/classesMana")
public class ClassesController {

	@Resource
	private ClassesService classesService;
	
	@RequestMapping("/listPageClasses")
	public void ListAllClasses(HttpServletResponse response)throws Exception{
		List<Classes> list = classesService.listPageClasses("");
		JSONObject jsonObject = new JSONObject();
		JsonConfig jsonConfig = new JsonConfig();
		JSONArray jsonArray = JSONArray.fromObject(list, jsonConfig);
		jsonObject.put("code", 0);
		jsonObject.put("data", jsonArray);
		jsonObject.put("count", 0);
		ResponseUtil.write(response, jsonObject);
	}
	
	@RequestMapping("/saveClasses")
	public void saveClasses(Classes classes, HttpServletResponse response)throws Exception{
		int isSuccess  = 0;
		if(null == classes.getCid() || "".equals(classes.getCid())){
			isSuccess = classesService.saveClasses(classes);
		}else{
			isSuccess = classesService.updateClasses(classes);
		}
		ResponseUtil.write(response, isSuccess);
	}
	
	@RequestMapping("/deleteClasses")
	public void deleteClasses(String str, HttpServletResponse response)throws Exception{
		int isSuccess  = classesService.deleteClasses(str);
		ResponseUtil.write(response, isSuccess);
	}
}
